package com.example;

import com.alibaba.druid.support.http.StatViewServlet;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import java.util.HashMap;

@ComponentScan({"com.example.common.config","com.example.redis.*"})
@SpringBootApplication
@MapperScan("com.example.crud.dao")
public class EsApplication {

    public static void main(String[] args) {
        SpringApplication.run(EsApplication.class, args);
    }

    // 后台监控
    @Bean
    public ServletRegistrationBean statViewServlet(){
        ServletRegistrationBean<StatViewServlet> bean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*");

        HashMap<String, String> initParameters = new HashMap<>();
        // 增加配置项
        initParameters.put("loginUsername","admin");
        initParameters.put("loginPassword","123456");
        //如果为空所有人都可以访问，如果localhost本机可以访问，如果具体的ip值则具体的值
        initParameters.put("allow","localhost");
        // 关于其他配置可以在类ResourceServlet下查看

        // 禁止xu访问       initParameters.put("xu","192.168.1.**");

        // 后台需要有人登陆
        bean.setInitParameters(initParameters);
        return bean;
    }
}
